﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class contest
    {
        public static dynamic deleteContestProblem(int cid, char ps)
        {
            var sql = new Sql.SqlDataContext();
            var p = sql.ContestProblem.FirstOrDefault(row => row.ps == ps && row.cid == cid);
            if (p == null)
            {
                return new
                {
                    success = false,
                    msg = "题目不存在"
                };
            }

            // Delete ContestSolve
            sql.ContestSolve.DeleteAllOnSubmit(sql.ContestSolve.Where(row => row.ps == ps && row.cid == cid));

            // Delete Status
            sql.ContestStatus.DeleteAllOnSubmit(sql.ContestStatus.Where(row => row.ps == ps && row.cid == cid));

            // Delete Problem
            var pro = sql.ContestProblem.FirstOrDefault(row => row.ps == ps && row.cid == cid);
            if(pro != null) sql.ContestProblem.DeleteOnSubmit(pro);

            sql.SubmitChanges();
            return new
            {
                success = true
            };
        }
    }
}
